import requests
from lxml import etree
if __name__ == '__main__':
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36'
    }
    url = 'https://www.aqistudy.cn/historydata/'
    response = requests.get(url=url,headers=headers).text
    tree = etree.HTML(response)
    all_city = []
    '''   分开解析数据   '''
    # 热门城市
    hot_city_list = tree.xpath('//div[@class="bottom"]/ul/li')
    for city in hot_city_list:
        city_name = city.xpath('./a/text()')[0]
        all_city.append(city_name)
    # 全部城市
    city_list = tree.xpath('//div[@class="bottom"]/ul/div/li')
    for city in city_list:
        city_name = city.xpath('./a/text()')[0]
        all_city.append(city_name)
    print(all_city)

    '''  一块解析数据  '''
    all_city2 = []
    all_city_list = tree.xpath('//div[@class="bottom"]/ul/li | //div[@class="bottom"]/ul/div/li')
    for city in all_city_list:
        city_name = city.xpath('./a/text()')[0]
        all_city2.append(city_name)
    print(all_city2)

